import moment from 'moment'
import Vue from 'vue'

// 数字格式化
export const dateformat = (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') =>
  moment(dataStr).format(pattern)

// 如果是小数,保留小数点后两位,如果是整数还是整数
export const floatToFixed = (number, config) => {
  const { num = 2, integer = false } = config || {}
  const _number = number || 0
  const isFloat = String(_number).indexOf('.') > -1
  if ((!integer && !isFloat) || !_number.toFixed) {
    return _number
  }
  return _number.toFixed(num)
}

/* ---------- 过滤器 --------start---------*/
Vue.filter('dateformat', dateformat)
Vue.filter('floatToFixed', floatToFixed)
/* ----------过滤器 --------start---------*/
